home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 323_01 / tess.c < prev    next >
C/C++ Source or Header  |  1990-08-04  |  48KB  |  2,208 lines

  1. /*--------------------------------------------------------------------------*\
  2. | TESS.C                                                                     |
  3. \*--------------------------------------------------------------------------*/
  4.  
  5. /*
  6.   Beyond The Tesseract   V2.03   (C) 1990 David Lo
  7.  
  8.   TRS-80
  9.     1.0  : 05/29/83 :
  10.     1.7  : 03/16/86 :
  11.  
  12.   MS-DOS
  13.     2.0  : 10/01/88 :
  14.     2.01 : 03/  /89 :
  15.     2.02 : 10/04/89 : Fixed probability message,
  16.                       Got rid of title screen when game ends.
  17.     2.03 : 01/22/90 : Added hint for field puzzle.
  18.          : 02/05/90 : "look" without noun will finally print the current room.
  19. */
  20.  
  21. #include <ctype.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24.  
  25. #include "adv-def.h"
  26. #include "parser.h"
  27. #include "tess-def.h"
  28.  
  29. /*------------------------------------------------------------*/
  30. /* on some PC clones (e.g. mine), scrolling the screen when printing a '\n'
  31.    with the conio.h routines (e.g. putch('\n') or cprintf('\n')) is much slower
  32.    than the stdio.h routines.
  33. */
  34. nl()  {  putchar('\n');  }
  35.  
  36. /*----------------------------*/
  37. /* if tty-mode, then using standard library functions for I/O, and ignore the
  38.    screen I/O functions
  39. */
  40. #ifdef tty
  41.  
  42. #define cprintf printf
  43. #define cputs printf
  44. #define prints puts
  45.  
  46. #define clrscr()
  47. #define clreol()
  48. #define gotoxy(x,y)
  49.  
  50. /* if non-tty-mode, use console IO library
  51. */
  52. #else
  53.  
  54. #include <conio.h>
  55.  
  56. prints( char *s )
  57. {
  58.   cputs( s );
  59.   nl();
  60. }
  61.  
  62. #endif
  63.  
  64. /*----------------------------*/
  65. int get_enter()
  66. {
  67.   int i=0, ch;
  68.  
  69.   while ((ch=getchar()) != '\n')
  70.     i+=ch;
  71.   return (i);
  72. }
  73.  
  74. /*----------------------------*/
  75. /* enter aux. object (e.g. Give XXX to AUX)
  76. */
  77. int InputNoun( char *prompt, char *noun )
  78. {
  79.   int nn;
  80.  
  81.   cprintf( prompt );
  82.   gets( noun );
  83.   nn = GetNounNum( noun );
  84.   resize_word( noun );
  85.   return( nn );
  86. }
  87.  
  88. /*------------------------------------------------------------*/
  89. /* Adventure dependent stuff
  90. */
  91.  
  92. int
  93.   print_room,         /* flag for updating room after command */
  94.  
  95.   curr_loc,           /* current location */
  96.   curr_lev,           /* current level */
  97.   level_loc [ 4 ],    /* current location for diff. levels */
  98.   zap,                /* flag set when game over */
  99.                       /*   1=quit   2=wrong password   3=right password */
  100.  
  101.   sleep_lev,          /* which level player was in when sleeping */
  102.  
  103.                       /* flags are 0=false/haven't done, 1=true/done */
  104.                       /* unless otherwise noted */
  105.  
  106.   cc,                 /* coil status: 0=normal  b1=cooled  b2=magnetized */
  107.   wa,                 /* water alien */
  108.   ep,                 /* eat pills */
  109.   dr,                 /* dice roll counter */
  110.   af,                 /* audio filter inserted */
  111.   gp,                 /* get password */
  112.   mi,                 /* message: bits 0,1,2,3 = parts found */
  113.   ti,                 /* think idea */
  114.   kp,                 /* kick projector */
  115.  
  116.   dc [ 3 ],           /* each dice roll, dc[i]<33 */
  117.   sum                 /* sum = sigma( dc ) < 100  */
  118.   ;
  119.  
  120. /*----------------------------*/
  121. InitAdv()
  122. {
  123.   int i;
  124.  
  125.   for ( i=1; i<MaxObjs; i++ )
  126.   {
  127.     obj[i].loc = obj[i].init_loc;
  128.   }
  129.  
  130.   level_loc[1] = 2;
  131.   level_loc[2] = 25;
  132.   level_loc[3] = 29;
  133.  
  134.   curr_lev = 1;
  135.   curr_loc = level_loc [ curr_lev ];
  136.  
  137.   zap = cc = wa = ep = dr = af = gp = mi = ti = kp = 0;
  138.  
  139.   for ( sum=0, i=0; i<3; i++ )
  140.     sum += (dc [i] = rand() & 31);
  141.  
  142.   print_room = 1;
  143. }
  144.  
  145. /*------------------------------------------------------------*/
  146. /* Message routines
  147. */
  148.  
  149. /*----------------------------*/
  150. PrintMess( int i )
  151. {
  152.   switch ( i )
  153.   {
  154.     case 1: prints("Nothing special happens."); break;
  155.     case 2: prints("That isn't possible."); break;
  156.     case 3: prints("Doesn't work."); break;
  157.     case 4: prints("Can't do that yet."); break;
  158.     case 5: prints("OK."); break;
  159.     case 6: prints("How?"); break;
  160.     case 7: cprintf("You have nothing to %s with.", cmd.verb ); nl(); break;
  161.   }
  162. }
  163.  
  164. not_happen() {  PrintMess( 1 );  }
  165. not_poss()   {  PrintMess( 2 );  }
  166. not_work()   {  PrintMess( 3 );  }
  167. not_yet()    {  PrintMess( 4 );  }
  168. ok()         {  PrintMess( 5 );  }
  169. how()        {  PrintMess( 6 );  }
  170.  
  171. /*------------------------------------------------------------*/
  172. /* Object routines
  173. */
  174.  
  175. /*----------------------------*/
  176. int CheckObjAttr( int nn, int mask )
  177. {
  178.   return ( obj [nn].attr & mask );
  179. }
  180.  
  181. #define CanGetObj(i) CheckObjAttr((i),1)
  182. #define CanLookObj(i) CheckObjAttr((i),4)
  183.  
  184. /*----------------------------*/
  185. CarryObj( int nn )
  186. {
  187.   obj [nn].loc = -curr_lev;
  188. }
  189.  
  190. int CarryingObj( int nn )
  191. {
  192.   return ( obj [nn].loc == -curr_lev );
  193. }
  194.  
  195. /*----------------------------*/
  196. WearObj( int nn )
  197. {
  198.   obj [nn].loc = -curr_lev - 3;
  199. }
  200.   
  201. int WearingObj( int nn )
  202. {
  203.   return ( obj [nn].loc == -curr_lev-3 );
  204. }
  205.  
  206. /*----------------------------*/
  207. int ObjOnPlayer( int nn )
  208. {
  209.   return ( CarryingObj(nn) || WearingObj(nn) );
  210. }
  211.  
  212. /*----------------------------*/
  213. DropObj( int nn )
  214. {
  215.   obj [nn].loc = curr_loc;
  216. }
  217.  
  218. int ObjInRoom( int nn )
  219. {
  220.   return ( obj [nn].loc == curr_loc );
  221. }
  222.  
  223. /*----------------------------*/
  224. JunkObj( int nn )
  225. {
  226.  obj [nn].loc = 0;
  227. }
  228.  
  229. /* replace object nn with object new_nn
  230. */
  231. ReplaceObj( int nn, int new_nn )
  232. {
  233.   obj [new_nn].loc = obj [nn].loc;
  234.   obj [nn].loc = 0;
  235. }
  236.  
  237. /*----------------------------*/
  238. /* See if an object is accessible.  This means the object is being
  239.    carried/worn, is in the same room, is a concept noun (e.g. north),
  240.    is part of the room (e.g. field), or is part of another object
  241.    (e.g. button).
  242. */
  243. int ObjIsPresent( int nn )
  244. {
  245.   if ( (nn>=o_north) && (nn<=o_invent) )   /* direction, "inventory" */
  246.     return (1);               /* always available */
  247.  
  248.   else if ( (nn>=o_buttons) && (nn<=o_four) )  /* buttons */
  249.     return ( ObjIsPresent(o_proj) );           /* on projector */
  250.  
  251.   else if ( (nn==o_liquid) && (obj[nn].loc==-8) )  /* contained fluid */
  252.     return ( ObjIsPresent(o_bottle) );             /* in Klein bottle */
  253.  
  254.   else
  255.     return ( ObjInRoom(nn) || CarryingObj(nn) || WearingObj(nn) );
  256. }
  257.  
  258. /*------------------------------------------------------------*/
  259. /* Room routines
  260. */
  261.  
  262. /*----------------------------*/
  263. /* predicates to return check whether the player in in a certain world
  264. */
  265. int InComplex( int rn )
  266. {
  267.   return ( rn==1 || rn==2 || rn==7 || rn==8 );
  268. }
  269.  
  270. int InMirrorWorld( int rn )
  271. {
  272.   return ( rn==4 || (rn>=9 && rn<=13) );
  273. }
  274.  
  275. int InMathWorld( int rn )
  276. {
  277.   return ( rn==3 || rn==5 || (rn>=14 && rn<=17) );
  278. }
  279.  
  280. int InSpectralWorld( int rn )
  281. {
  282.   return ( rn==6 || (rn>=18 && rn<=22) );
  283. }
  284.  
  285. int InDreamWorld( int rn )
  286. {
  287.   return ( curr_lev==2 || (rn>=23 && rn<=28) || rn==35 );
  288. }
  289.  
  290. int InBookWorld( int rn )
  291. {
  292.   return ( curr_lev==3 || (rn>=29 && rn<=34) );
  293. }
  294.  
  295. /*----------------------------*/
  296. PrintCurrRoom()
  297. {
  298.   static int stop_line=1;
  299.   int i,flag, len,currx;
  300.   char *s;
  301.  
  302. #ifndef tty
  303.   /* clear window area from previous time
  304.   */
  305.   for ( i=stop_line; i>=1; i-- )
  306.   {
  307.     gotoxy( 1, i );
  308.     clreol();
  309.   }
  310. #else
  311.   cprintf("------------------------------------------------------------------------------");
  312.   nl();
  313. #endif
  314.  
  315.   cprintf("You are %s.", room [ curr_loc ].name ); nl();
  316.  
  317.   prints("You see around you:");
  318.   clreol();
  319.   flag=0;
  320.   currx=0;
  321.   for ( i=1; i<MaxObjs; i++ )
  322.     if (ObjInRoom(i))
  323.     {
  324.       s = obj[i].name;
  325.       len = strlen(s);
  326.       if (currx+ len + 3 > 78 ) { currx=0; nl(); clreol(); }
  327.       cprintf("  %s.", s );
  328.       currx += len+3;
  329.       flag=1;
  330.     }
  331.   if (!flag)
  332.     prints("  Nothing special.");
  333.   else
  334.     { nl(); clreol(); }
  335.  
  336.   prints("Exits:");
  337.   clreol();
  338.   flag=0;
  339.   for ( i=0; i<MaxDirs; i++ )
  340.     if ( room [curr_loc].link [i] )
  341.     {
  342.       cprintf("  %s.", obj[i+1].name );
  343.       flag=1;
  344.     }
  345.   if (!flag) cprintf("  none.");
  346.   nl();
  347.  
  348. #ifdef tty
  349.   nl();
  350. #else
  351.   prints("------------------------------------------------------------------------------");
  352.   stop_line = wherey();  /* stop line is the line after the separator bar */
  353.   g